<template>
    <view class="container">
        <block v-if="init">
            <view class="address padding" v-if="isNeedAddress">
                <select-address
                    @__l="__l($event, { eventOpts: [['^input', [['__set_model', ['', 'address', '$event', []]]]]] })"
                    @input="__e($event, { eventOpts: [['^input', [['__set_model', ['', 'address', '$event', []]]]]] })"
                    :data-event-opts="[['^input', [['__set_model', ['', 'address', '$event', []]]]]]"
                    :isShowPhone="true"
                    :value="address"
                    vueId="233996f0-1"
                ></select-address>
            </view>
            <split-line @__l="__l" vueId="233996f0-2"></split-line>
            <view class="products">
                <sku-item @__l="__l" class="sku" :info="item" :vueId="'233996f0-3-' + index" v-for="(item, index) in products" :key="index"></sku-item>
            </view>
            <split-line @__l="__l" vueId="233996f0-4"></split-line>
            <view class="list padding">
                <view class="list-item">
                    <view class="body">商品总价</view>
                    <view class="arrow-right bold">
                        <view>
                            <price-display @__l="__l" :info="order" prefix="product_" vueId="233996f0-5"></price-display>
                        </view>
                    </view>
                </view>
                <view class="list-item">
                    <view class="body">优惠券</view>
                    <view @tap="__e" class="arrow-right bold" :data-event-opts="[['tap', [['e0', ['$event']]]]]" v-if="currentCoupon.id">
                        <text class="meta red">{{ '- ¥' + $root.f0 }}</text>
                        <text class="new-iconfont icon-arrow-right"></text>
                    </view>
                    <view @tap="__e" class="arrow-right" :data-event-opts="[['tap', [['e1', ['$event']]]]]" v-else>
                        <text class="meta" v-if="$root.g0">{{ $root.g1 + '张可用' }}</text>
                        <text class="meta" v-else>无可用</text>
                        <text class="new-iconfont icon-arrow-right"></text>
                    </view>
                </view>
                <view class="list-item" v-if="order.cover_type">
                    <view class="body">兑换类型</view>
                    <view class="arrow-right bold">
                        <text class="meta" v-if="order.cover_type === 'chip'">碎片兑换</text>
                        <block v-else>
                            <text class="meta" v-if="order.cover_type === 'score'">{{ scoreAlias + '兑换' }}</text>
                        </block>
                    </view>
                </view>
                <view class="list-item" v-if="order.cover_discount">
                    <view class="body">兑换优惠</view>
                    <view class="arrow-right bold">
                        <text class="meta red">{{ '- ¥' + $root.f1 }}</text>
                    </view>
                </view>
                <view class="list-item">
                    <view class="body">红包抵扣</view>
                    <view class="arrow-right bold">
                        <text class="meta red">
                            <block v-if="order.redpack">-</block>
                            {{ '¥' + $root.f2 }}
                        </text>
                        <switch
                            @change="__e"
                            :checked="order.is_use_redpack"
                            class="redpack-switch"
                            :data-event-opts="[['change', [['redpackSwitchChange', ['$event']]]]]"
                            v-if="order.redpack"
                        ></switch>
                    </view>
                </view>
                <view class="list-item" v-if="order.max_useable_score">
                    <view class="body">{{ '' + scoreAlias + '抵扣' }}</view>
                    <view class="arrow-right bold">
                        <text class="meta">{{ '' + order.max_useable_score + scoreAlias }}</text>
                        <text class="meta red" style="margin-left: 10rpx" v-if="order.score_discount">{{ '-¥' + $root.f3 }}</text>
                        <switch
                            @change="__e"
                            :checked="order.is_use_score"
                            class="redpack-switch"
                            :data-event-opts="[['change', [['scoreSwitchChange', ['$event']]]]]"
                            v-if="order.max_useable_score"
                        ></switch>
                    </view>
                </view>
                <view class="list-item">
                    <view class="body">运费</view>
                    <view class="arrow-right bold" v-if="order.carriage_type === 2">
                        <text class="meta red">到付</text>
                    </view>
                    <view class="arrow-right bold" v-else>
                        <text class="meta red">{{ '+ ¥' + $root.f4 }}</text>
                    </view>
                </view>
                <view class="list-item">
                    <view class="body">实付</view>
                    <view class="arrow-right bold">
                        <text class="meta">{{ '¥' + $root.f5 }}</text>
                    </view>
                </view>
                <view class="list-item">
                    <view class="body">备注</view>
                    <view class="arrow-right remark">
                        <input
                            @input="__e"
                            :data-event-opts="[['input', [['__set_model', ['', 'remark', '$event', []]]]]]"
                            placeholder="请输入您对商家说的话"
                            placeholderClass="placeholder"
                            type="text"
                            :value="remark"
                        />
                    </view>
                </view>
            </view>
            <view style="height: 160rpx"></view>
            <view class="footer-actions safe-area-bottom">
                <view class="price-c">
                    <price-display @__l="__l" :info="order" prefix="pay_" vueId="233996f0-6"></price-display>
                </view>
                <i-button
                    @__l="__l($event, { eventOpts: [['^click', [['disableMultiClick', ['$0'], ['payOrder']]]]] })"
                    @click="__e($event, { eventOpts: [['^click', [['disableMultiClick', ['$0'], ['payOrder']]]]] })"
                    :data-event-opts="[['^click', [['disableMultiClick', ['$0'], ['payOrder']]]]]"
                    :round="true"
                    size="small"
                    vueId="233996f0-7"
                    :vueSlots="['default']"
                >
                    <text>确认订单</text>
                </i-button>
            </view>
            <usable-coupon-popup
                @__l="
                    __l($event, {
                        eventOpts: [
                            ['^change', [['couponChange']]],
                            ['^close', [['e2']]]
                        ]
                    })
                "
                @change="
                    __e($event, {
                        eventOpts: [
                            ['^change', [['couponChange']]],
                            ['^close', [['e2']]]
                        ]
                    })
                "
                @close="
                    __e($event, {
                        eventOpts: [
                            ['^change', [['couponChange']]],
                            ['^close', [['e2']]]
                        ]
                    })
                "
                :currentCoupon="currentCoupon"
                :data-event-opts="[
                    ['^change', [['couponChange']]],
                    ['^close', [['e2']]]
                ]"
                :unusableCoupons="unusableCoupons"
                :usableCoupons="usableCoupons"
                vueId="233996f0-8"
                v-if="couponsVisible"
            ></usable-coupon-popup>
        </block>
        <no-data @__l="__l" vueId="233996f0-9" v-else></no-data>
    </view>
</template>

<script>
import selectAddress from '@/components/SelectAddress/SelectAddress';
import skuItem from '@/components/SkuItem/SkuItem';
import priceDisplay from '@/components/PriceDisplay/PriceDisplay';
import usableCouponPopup from '@/components/UsableCouponPopup/UsableCouponPopup';
import noData from '@/components/NoData/NoData';
import splitLine from '@/components/SplitLine/index';
import iButton from '@/components/Button/index';
import tabBar from '@/components/TabBar/tabBar';
(global.webpackJsonp = global.webpackJsonp || []).push([
    ['pages/orderPreview/index'],
    {
        3879: function (e, t, r) {
            'use strict';

            (function (e, t) {
                var n = r('4ea4');
                r('18ba');
                n(r('66fd'));
                var i = n(r('3f31'));
                e.__webpack_require_UNI_MP_PLUGIN__ = r;
                t(i.default);
            }.call(this, r('bc2e').default, r('543d').createPage));
        },
        '3f31': function (e, t, r) {
            'use strict';

            r.r(t);
            var n = r('7627');
            var i = r('6f1e');
            for (var o in i) {
                if (['default'].indexOf(o) < 0) {
                    (function (e) {
                        r.d(t, e, function () {
                            return i[e];
                        });
                    })(o);
                }
            }
            r('5b30');
            var s = r('f0c5');
            var u = Object(s.a)(i.default, n.b, n.c, false, null, null, null, false, n.a, void 0);
            t.default = u.exports;
        },
        '5b30': function (e, t, r) {
            'use strict';

            var n = r('8efa');
            r.n(n).a;
        },
        '6f1e': function (e, t, r) {
            'use strict';

            r.r(t);
            var n = r('dd60');
            var i = r.n(n);
            for (var o in n) {
                if (['default'].indexOf(o) < 0) {
                    (function (e) {
                        r.d(t, e, function () {
                            return n[e];
                        });
                    })(o);
                }
            }
            t.default = i.a;
        },
        7627: function (e, t, r) {
            'use strict';

            r.d(t, 'b', function () {
                return i;
            });
            r.d(t, 'c', function () {
                return o;
            });
            r.d(t, 'a', function () {
                return n;
            });
            var n = {
                SelectAddress: function () {
                    return r.e('components/SelectAddress/SelectAddress').then(r.bind(null, '8a38'));
                },
                SkuItem: function () {
                    return Promise.all([r.e('common/vendor'), r.e('components/SkuItem/SkuItem')]).then(r.bind(null, '3c3e'));
                },
                PriceDisplay: function () {
                    return r.e('components/PriceDisplay/PriceDisplay').then(r.bind(null, '6b05'));
                },
                UsableCouponPopup: function () {
                    return r.e('components/UsableCouponPopup/UsableCouponPopup').then(r.bind(null, '3858'));
                },
                NoData: function () {
                    return r.e('components/NoData/NoData').then(r.bind(null, 'cafe'));
                }
            };
            var i = function () {
                var that = this;
                var t = (that.$createElement, that._self._c, that.init && that.currentCoupon.id ? that._f('priceToFixed')(that.order.coupon_discount) : null);
                if (that.init && !that.currentCoupon.id) {
                    var r = that.usableCoupons.length;
                } else {
                    var r = null;
                }
                if (that.init && !that.currentCoupon.id && r) {
                    var n = that.usableCoupons.length;
                } else {
                    var n = null;
                }
                var i = that.init && that.order.cover_discount ? that._f('priceToFixed')(that.order.cover_discount) : null;
                var o = that.init ? that._f('priceToFixed')(that.order.redpack) : null;
                var s = that.init && that.order.max_useable_score && that.order.score_discount ? that._f('priceToFixed')(that.order.score_discount) : null;
                var u = that.init && 2 !== that.order.carriage_type ? that._f('priceToFixed')(that.order.carriage) : null;
                var d = that.init ? that._f('priceToFixed')(that.order.price) : null;
                that._isMounted ||
                    ((that.e0 = function (t) {
                        that.couponsVisible = true;
                    }),
                    (that.e1 = function (t) {
                        that.couponsVisible = true;
                    }),
                    (that.e2 = function (t) {
                        that.couponsVisible = false;
                    }));
                that.$mp.data = Object.assign(
                    {},
                    {
                        $root: {
                            f0: t,
                            g0: r,
                            g1: n,
                            f1: i,
                            f2: o,
                            f3: s,
                            f4: u,
                            f5: d
                        }
                    }
                );
            };
            var o = [];
        },
        '8efa': function (e, t, r) {},
        dd60: function (e, t, r) {
            'use strict';

            (function (e) {
                var n = r('4ea4');
                Object.defineProperty(t, '__esModule', {
                    value: true
                });
                t.default = void 0;
                var i = n(r('9523'));
                var o = n(r('452d'));
                var s = n(r('82c0'));
                var u = r('26cb');
                function d(e, t) {
                    var r = Object.keys(e);
                    if (Object.getOwnPropertySymbols) {
                        var n = Object.getOwnPropertySymbols(e);
                        if (t) {
                            n = n.filter(function (t) {
                                return Object.getOwnPropertyDescriptor(e, t).enumerable;
                            });
                        }
                        r.push.apply(r, n);
                    }
                    return r;
                }
                function c(e) {
                    for (var t = 1; t < arguments.length; t++) {
                        var r = null != arguments[t] ? arguments[t] : {};
                        t % 2
                            ? d(Object(r), true).forEach(function (t) {
                                  (0, i.default)(e, t, r[t]);
                              })
                            : Object.getOwnPropertyDescriptors
                            ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r))
                            : d(Object(r)).forEach(function (t) {
                                  Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(r, t));
                              });
                    }
                    return e;
                }
                var a = {
                    mixins: [o.default],
                    components: {
                        SplitLine: function () {
                            r.e('components/SplitLine/index')
                                .then(
                                    function () {
                                        return resolve(r('2993'));
                                    }.bind(null, r)
                                )
                                .catch(r.oe);
                        },
                        IButton: function () {
                            r.e('components/Button/index')
                                .then(
                                    function () {
                                        return resolve(r('93c4'));
                                    }.bind(null, r)
                                )
                                .catch(r.oe);
                        }
                    },
                    data: function () {
                        return {
                            address: {},
                            order: {
                                is_use_redpack: 'unselect'
                            },
                            isNeedAddress: 0,
                            skus: [],
                            seckillId: '',
                            groupPriceUuid: '',
                            products: [],
                            remark: '',
                            init: false,
                            couponsVisible: false,
                            unusableCoupons: [],
                            usableCoupons: [],
                            currentCoupon: {},
                            current: 0,
                            animationData: {},
                            animationData2: {},
                            coverType: '',
                            _source: ''
                        };
                    },
                    computed: c(
                        c({}, (0, u.mapGetters)(['token'])),
                        {},
                        {
                            totalPrice: function () {
                                return this.order.price;
                            }
                        }
                    ),
                    onLoad: function (t) {
                        var that = this;
                        this.seckillId = t.seckillId;
                        this.groupPriceUuid = t.groupPriceUuid;
                        this.coverType = t.coverType;
                        this.skus = JSON.parse(t.skus);
                        this._source = t._source;
                        e.$on('selectAddress', function (e) {
                            that.address = e;
                            that.getOrderInfo();
                        });
                    },
                    onUnload: function () {
                        e.$off('selectAddress', function (e) {
                            console.log('移除 selectAddress 自定义事件');
                        });
                    },
                    onShow: function () {
                        if (this.token && !this.address.id) {
                            this.getOrderInfo();
                        }
                    },
                    methods: {
                        redpackSwitchChange: function (e) {
                            this.order.is_use_redpack = e.detail.value ? 1 : 0;
                            this.getOrderInfo();
                        },
                        scoreSwitchChange: function (e) {
                            this.order.is_use_score = e.detail.value ? 1 : 0;
                            this.getOrderInfo();
                        },
                        couponChange: function (e) {
                            e.id === this.currentCoupon.id ? ((this.currentCoupon = {}), this.getOrderInfo()) : ((this.currentCoupon = e), this.getOrderInfo());
                        },
                        createOrder: function () {
                            e.showLoading({
                                title: '加载中',
                                mask: true
                            });
                            this.$api
                                .emit('order.store', {
                                    payment: 'miniapp',
                                    skus: this.skus,
                                    coupon_id: this.currentCoupon && this.currentCoupon.id,
                                    seckill_id: this.seckillId,
                                    group_price_uuid: this.groupPriceUuid,
                                    address_id: this.address && this.address.id,
                                    remark: this.remark,
                                    cover_type: this.coverType,
                                    is_use_redpack: this.order.is_use_redpack,
                                    is_use_score: this.order.is_use_score,
                                    _source: this._source
                                })
                                .then(function (t) {
                                    var r = t.data;
                                    var n = t.data.order;
                                    if (!r.is_need_pay) {
                                        e.showToast({
                                            title: '支付成功，正在跳转~',
                                            icon: 'none'
                                        });
                                        setTimeout(function () {
                                            e.redirectTo({
                                                url: '/pages/orderDetail/index?uuid=' + n.uuid
                                            });
                                        }, 1500);
                                        return false;
                                    }
                                    s.default.pay(
                                        c(
                                            c({}, r),
                                            {},
                                            {
                                                pay_type: r.pay_type,
                                                success: function () {
                                                    e.showToast({
                                                        title: '支付成功',
                                                        icon: 'none'
                                                    });
                                                    setTimeout(function () {
                                                        e.redirectTo({
                                                            url: '/pages/orderList/index?status=deliver_pending'
                                                        });
                                                    }, 1500);
                                                },
                                                fail: function () {
                                                    e.showToast({
                                                        title: '支付失败',
                                                        icon: 'none'
                                                    });
                                                    e.redirectTo({
                                                        url: '/pages/orderDetail/index?uuid=' + n.uuid
                                                    });
                                                }
                                            }
                                        )
                                    );
                                    e.hideLoading();
                                })
                                .catch(function (t) {
                                    e.hideLoading();
                                });
                        },
                        payOrder: function () {
                            var that = this;
                            !this.isNeedAddress || this.address.id
                                ? e.requestSubscribeMessage({
                                      tmplIds: [this.miniappSubscribeIds.order_delivered, this.miniappSubscribeIds.order_paid],
                                      complete: function (e) {
                                          that.createOrder();
                                      }
                                  })
                                : e.showToast({
                                      title: '未添加收货地址',
                                      icon: 'none'
                                  });
                        },
                        getOrderInfo: function () {
                            var that = this;
                            e.showLoading({
                                title: '加载中',
                                mask: true
                            });
                            this.$api
                                .emit('order.preview.store', {
                                    skus: this.skus,
                                    address_id: this.address && this.address.id,
                                    seckill_id: this.seckillId,
                                    group_price_uuid: this.groupPriceUuid,
                                    coupon_id: this.currentCoupon.id,
                                    cover_type: this.coverType,
                                    is_use_redpack: this.order.is_use_redpack,
                                    is_use_score: this.order.is_use_score ? 1 : 0
                                })
                                .then(function (r) {
                                    e.hideLoading();
                                    that.init = true;
                                    that.order = r.data.order;
                                    that.products = r.data.order.skus;
                                    that.unusableCoupons = r.data.order.coupons.unusable;
                                    that.usableCoupons = r.data.order.coupons.usable;
                                    that.address = r.data.address;
                                    that.isNeedAddress = r.data.is_need_address;
                                    if (r.data.tips) {
                                        e.showModal({
                                            content: r.data.tips,
                                            title: '温馨提示'
                                        });
                                    }
                                });
                        }
                    }
                };
                t.default = a;
            }.call(this, r('543d').default));
        }
    },
    [['3879', 'common/runtime', 'common/vendor']]
]);
</script>
<style>
@import './index.css';
</style>
